package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {


    @Select("select count(*) from orders where status=#{i}")
    Integer GetStatistics(int i) ;


    @Select("select * from orders where id=#{id}")
    Orders FindById(Integer id);


    Page<Orders> PageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Update("UPDATE orders SET status = 5 WHERE id = #{id}")
    void CompleteById(Integer id);

    @Update("UPDATE orders SET status = 6, cancel_reason = #{cancelReason} WHERE id = #{id}")
    void Cancel(Long id, String cancelReason);

    @Update("UPDATE orders SET status = 6,  rejection_reason= #{rejectionReason} WHERE id = #{id}")
    void Rejection(Long id, String rejectionReason);

    @Update("UPDATE orders SET status = 4  WHERE id = #{id}")
    void delivery(Integer id);

    void Update(Orders orders);

    Integer countByMap(Map map);

    Double sumByMap(Map map);

    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);

    @Update("update orders set status=6 where id=#{id}")
    void cancelOrderById(Integer id);

    void addOrder(Orders orders);

    @Select("select id from orders where number=#{number}")
    Long FindId(String number);
}
